import collections
class Solution(object):
    def numOfWays(self, n):
        base = 10 ** 9 + 7
        def dfs(val):
            last0 = val % 3
            val = val // 3
            last1 = val % 3
            last2 = val // 3
            if last0 != last1 and last1 != last2:
                return True
            else:
                return False

        def judge(val1, val2):
            up_last0 = val1 % 3
            val1 = val1 // 3
            up_last1 = val1 % 3
            up_last2 = val1 // 3
            down_last0 = val2 % 3
            val2 = val2 // 3
            down_last1 = val2 % 3
            down_last2 = val2 // 3
            return up_last0 != down_last0 and up_last1 != down_last1 and up_last2 != down_last2

        st = collections.defaultdict(int)
        for val in range(27):
            if dfs(val):
                st[val] = 1

        for _ in range(1, n):
            next_st = collections.defaultdict(int)
            for val1 in range(27):
                for val2 in range(27):
                    if dfs(val1) and dfs(val2) and judge(val1, val2):
                        next_st[val2] = (st[val1] + next_st[val2]) % base
            st = next_st
        return sum(list(st.values())) % base

data = Solution()
n = 2
print(data.numOfWays(n))
